package cqrtplm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.hustcad.plm.pdm.file.handler.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.RtCfgDspfDemandMainQueryDTO;
import cqrtplm.dto.thirdPartyAPI.RestAdapterMomOrderDTO;
import cqrtplm.service.IRtCfgDspfDemandMainService;
import cqrtplm.vo.MomApiResponseVO;
import cqrtplm.vo.RtCfgDspfDemandMainVO;
import cqrtplm.vo.TransitOrderResponseVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 需求主表Controller
 *
 * @author 江小雄
 * @date 2025-07-10
 */
@RestController
@RequestMapping(RouteConstant.RTCFGDSPFDEMANDMAIN + "v1")
public class RtCfgDspfDemandMainController
{
    @Autowired
    private IRtCfgDspfDemandMainService rtCfgDspfDemandMainService;

//    /**
//     * 查询需求主表列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(RtCfgDspfDemandMain rtCfgDspfDemandMain)
//    {9
//        startPage();
//        List<RtCfgDspfDemandMain> list = rtCfgDspfDemandMainService.selectRtCfgDspfDemandMainList(rtCfgDspfDemandMain);
//        return getDataTable(list);
//    }

    @PostMapping("/list")
    public PageInfo<RtCfgDspfDemandMainVO> list(@RequestBody RtCfgDspfDemandMainQueryDTO queryDTO) {
        PageInfo<RtCfgDspfDemandMainVO> page = null;
        //待办
        if("9".equals(queryDTO.getStatus())){
            page =  rtCfgDspfDemandMainService.selectPageListDaiban(queryDTO, queryDTO.getPageNum()==null ? 1: queryDTO.getPageNum(), queryDTO.getPageSize()==null ? 10: queryDTO.getPageSize());
        }else { //其他
            page =  rtCfgDspfDemandMainService.selectPageList(queryDTO, queryDTO.getPageNum()==null ? 1: queryDTO.getPageNum(), queryDTO.getPageSize()==null ? 10: queryDTO.getPageSize());
        }
        return page;
    }

    /**
     * 根据流程编码获取流程信息
     * @param flowCode
     * @return
     */
    @GetMapping("/getFlowDataByFlowCode")
    public ResponseResult getFlowDataByFlowCode(@RequestParam String flowCode) {
        return rtCfgDspfDemandMainService.getFlowDataByFlowCode(flowCode);
    }

    /**
     * 获取在途订单数据（MOM、CRM、SAP）
     * @param dto
     * @return
     */
    @PostMapping("/getTransitOrder")
    public ResponseResult getTransitOrder(@RequestBody RtCfgDspfDemandMainQueryDTO dto) {
        return rtCfgDspfDemandMainService.getTransitOrder(dto);
    }

//    /**
//     * 导出需求主表列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:export')")
//    @Log(title = "需求主表", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, RtCfgDspfDemandMain rtCfgDspfDemandMain)
//    {
//        List<RtCfgDspfDemandMain> list = rtCfgDspfDemandMainService.selectRtCfgDspfDemandMainList(rtCfgDspfDemandMain);
//        ExcelUtil<RtCfgDspfDemandMain> util = new ExcelUtil<RtCfgDspfDemandMain>(RtCfgDspfDemandMain.class);
//        util.exportExcel(response, list, "需求主表数据");
//    }
//
//    /**
//     * 获取需求主表详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:query')")
//    @GetMapping(value = "/{kid}")
//    public AjaxResult getInfo(@PathVariable("kid") String kid)
//    {
//        return success(rtCfgDspfDemandMainService.selectRtCfgDspfDemandMainByKid(kid));
//    }
//
//    /**
//     * 新增需求主表
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:add')")
//    @Log(title = "需求主表", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody RtCfgDspfDemandMain rtCfgDspfDemandMain)
//    {
//        return toAjax(rtCfgDspfDemandMainService.insertRtCfgDspfDemandMain(rtCfgDspfDemandMain));
//    }
//
//    /**
//     * 修改需求主表
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:edit')")
//    @Log(title = "需求主表", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody RtCfgDspfDemandMain rtCfgDspfDemandMain)
//    {
//        return toAjax(rtCfgDspfDemandMainService.updateRtCfgDspfDemandMain(rtCfgDspfDemandMain));
//    }
//
//    /**
//     * 删除需求主表
//     */
//    @PreAuthorize("@ss.hasPermi('system:main:remove')")
//    @Log(title = "需求主表", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{kids}")
//    public AjaxResult remove(@PathVariable String[] kids)
//    {
//        return toAjax(rtCfgDspfDemandMainService.deleteRtCfgDspfDemandMainByKids(kids));
//    }
}
